home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Learn C++ (CodeWarrior)
/
Chap 09.04 - virtual
/
virtual.cp
< prev
next >
Wrap
Text File
|
1995-10-21
|
1KB
|
81 lines
#include <iostream.h>
//--------------------------------------- Root
class Root
{
protected:
short num;
public:
Root( short numParam );
};
Root::Root( short numParam )
{
num = numParam;
cout << "Root constructor called\n";
}
//--------------------------------------- Base1
class Base1 : public virtual Root
{
public:
Base1();
};
Base1::Base1() : Root( 1 )
{
cout << "Base1 constructor called\n";
}
//--------------------------------------- Base2
class Base2 : public virtual Root
{
public:
Base2();
};
Base2::Base2() : Root( 2 )
{
cout << "Base2 constructor called\n";
}
//--------------------------------------- Derived
class Derived : public Base1, public Base2
{
public:
Derived();
short GetNum();
};
Derived::Derived() : Root( 3 )
{
cout << "Derived constructor called\n";
}
short Derived::GetNum()
{
return( num );
}
//--------------------------------------- main()
int main()
{
Derived myDerived;
cout << "-------\n"
<< "num = " << myDerived.GetNum();
return 0;
}